package com.example.admin.yuejian21.fragment;

//
import android.os.Bundle;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.admin.yuejian21.Bean.ClubDetail;
import com.example.admin.yuejian21.R;
import com.example.admin.yuejian21.Service.Service;

import it.sephiroth.android.library.picasso.Picasso;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.admin.yuejian21.Adapter.RenqiAdapter.id;


/**
 * A simple {@link Fragment} subclass.
 */
public class IntroFragment extends Fragment {

    private ClubDetail club;
    private ImageView View;
    private TextView addressView;
    private TextView phoneView;
    private TextView introView;
    private TextView nameView;

    private TextView timeView;


    String SessionID="060pn7sjorpnq5fp53kid5st54";




    public IntroFragment() {
        // Required empty public constructor
    }
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        addressView = (TextView) view.findViewById(R.id.textView_address);
        phoneView = (TextView) view.findViewById(R.id.textView_phone);
        timeView = (TextView) view.findViewById(R.id.textView_time);
        View =
                (ImageView) view.findViewById(R.id.imageView_tpic);
        nameView = (TextView) view.findViewById(R.id.textView_trainname);
        introView = (TextView) view.findViewById(R.id.club_intro);


        Retrofit retrofit = new Retrofit.Builder().baseUrl("http://172.24.10.175/workout/api.php/").addConverterFactory(GsonConverterFactory.create())
                .build();
        Service service = retrofit.create(Service.class);

        Call<ClubDetail> call = service.getclub(SessionID, id);
        call.enqueue(new Callback<ClubDetail>() {
            @Override
            public void onResponse(Call<ClubDetail> call, Response<ClubDetail> response) {
                club=response.body();

                if (club!= null) {
                    nameView.setText(club.getClub_contact());
                    introView.setText(club.getIntroduction());
                    addressView.setText(club.getProvince_name() +

                            club.getCity_name() + club.getDistrict_name()
                    );
                    phoneView.setText(club.getClub_tel());




                if(club.getClub_contact()!=null){ nameView.setText(club.getClub_contact());}
                introView.setText(club.getIntroduction());
                addressView.setText(club.getProvince_name()+

                        club.getCity_name() +club.getDistrict_name()
                );
                timeView.setText(club.getOpen_time());
                if(club.getClub_contact()!=null){phoneView.setText(club.getClub_tel());}
                nameView.setText(club.getClub_contact());
                if(!club.getThumb().equals(""))

                {
                    Picasso
                            .with(getActivity())

                            .load("http://172.24.10.175/workout/Uploads/"+club.getThumb());




                    if (club.getClub_contact() != null) {
                        nameView.setText(club.getClub_contact());
                    }
                    introView.setText(club.getIntroduction());

                    timeView.setText(club.getOpen_time());


                    phoneView.setText(club.getClub_tel());



                           // .into(View);




                }










                    if (!club.getThumb().equals(""))

                    {
                        Picasso
                                .with(getActivity())
                                .load("http://172.24.10.175/workout/Uploads/" + club.getThumb())


                                .into(View);


                    }
                }

            }

            @Override
            public void onFailure(Call<ClubDetail> call, Throwable t) {

            }
        });



    }



        @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_intro, container, false);
    }

}

